package com.example.demo.dao;

import com.example.demo.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 评论的数据库操作类
 */
public interface CommentDao extends JpaRepository<Comment,Integer> {
    /**
     * 根据圈子ID获取该圈子所有的评论列表
     * @param circleId
     * @return
     */
    @Query(value = "select c.*,u.nickname,u.avtar,(select nickname from user where id =    (select userId from comment " +
            "where id= (select replyId from comment where id=c.id))) as replyNickname from comment c " +
            "join user u on u.id = c.userId where circleId=?1 order by time desc limit ?2,?3"
            ,nativeQuery = true)
    List<Map<String,Object>> getComment(int circleId,int page,int pageSize);
    @Query(value = "select count (id) from comment where circleId=?1",nativeQuery = true)
    int getCoumt(int circleId);

    int getComment(int circleId);

    List<Map<String, Object>> getAdminComment(int circleId, int i, int pageSize);

    int getCount(int circleId);
}
